//
//  Task_Views_AppDelegate.m
//  Task Views
//
//  Created by Chris Karr on 2/17/09.
//  Copyright Chris J. Karr 2009 . All rights reserved.
//

#import "Task_Views_AppDelegate.h"

@implementation Task_Views_AppDelegate

- (NSString *) applicationSupportFolder 
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSApplicationSupportDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory ();
    return [basePath stringByAppendingPathComponent:@"Task Views"];
}

- (void) awakeFromNib
{
	NSFileManager * manager = [NSFileManager defaultManager];
	NSString * file = [[self applicationSupportFolder] stringByAppendingPathComponent:@"Database.bin"];
	
	if ([manager fileExistsAtPath:file])
	{
		NSSet * savedTasks = [NSUnarchiver unarchiveObjectWithFile:file];
		
		for (NSMutableDictionary * task in savedTasks)
			[tasks addObject:task];
	}

	[[NSNotificationCenter defaultCenter] postNotificationName:@"refresh_fields" object:nil];
}

// TODO Implement Undo Manager

/* - (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window {

 } */

- (IBAction) saveAction:(id)sender 
{
	NSLog (@"save the data");
}

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender 
{
	[[NSNotificationCenter defaultCenter] postNotificationName:@"quitting" object:nil];
	
	NSLog (@"confirm quit?");
	
    return NSTerminateNow;
}

@end
